﻿using JBeamLibrary.VehicleParts.Elements;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace JBeamLibrary.VehicleParts.Groups
{
    public class GlowMap : KeyedCollection<string, GlowMaterial>
    {
        #region CTORs

        /// <summary>Creates a new glow material collection</summary>
        public GlowMap()
        {

        }

        /// <summary>Creates a new glow material collection</summary>
        /// <param name="nodes"></param>
        public GlowMap(IEnumerable<GlowMaterial> glowMaterials)
        {
            AddRange(glowMaterials);
        }

        #endregion

        #region Methods

        /// <summary>Adds a collection of glow materials to the list</summary>
        /// <param name="glowMaterials"></param>
        public void AddRange(IEnumerable<GlowMaterial> glowMaterials)
        {
            foreach (var glowMaterial in glowMaterials)
                Add(glowMaterial);
        }

        /// <summary>Updates or adds the glow material with a matching name in the list</summary>
        /// <param name="glowMaterial"></param>
        public void UpdateAdd(GlowMaterial glowMaterial)
        {
            if (Contains(glowMaterial.Name))
                Remove(glowMaterial.Name);
            Add(glowMaterial);
        }

        /// <summary>Updates or adds glow materials of a given collection to the list</summary>
        /// <param name="glowMaterials"></param>
        public void UpdateAddRange(IEnumerable<GlowMaterial> glowMaterials)
        {
            foreach (var glowMaterial in glowMaterials)
                UpdateAdd(glowMaterial);
        }

        #endregion

        #region KeyedCollection

        protected override string GetKeyForItem(GlowMaterial item)
        {
            return item.Name;
        }

        #endregion
    }
}
